import { login } from '@/api/login.js'
import { info } from '@/api/user.js'
import { getToken } from '@/utils/auth.js'

const state = {
  token: getToken() || '',
  userInfo: ''
}

const mutations = {
  setToken(state, val) {
    state.token = val
    // setToken(val)
  },
  setUserInfo(state, val) {
    state.userInfo = val
  },
  logout(state) {
    state.token = ''
    state.userInfo = ''
  }
}

const actions = {
    // 
    async toLogin({ commit }, val) {
        const res = await login(val)
        commit('setToken', res.data.data.token)
        console.log('res', res);
    },
    async getUserInfo(store, val) {
        const res = await info(val)
        // console.log('111', res);

        store.commit('setUserInfo', res.data.data)
    }

}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
